package com.jewel.service.impl;

import com.jewel.mapper.TabProductMapper;
import com.jewel.model.IndexProduct;
import com.jewel.pojo.TabProduct;
import com.jewel.pojo.TabProductExample;
import com.jewel.service.IndexService;
import com.jewel.tools.Tools;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: 主模块业务类
 * 
 * @author DELL
 *
 * @since 2017.04.27
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private TabProductMapper tabProductMapper;

    /**
	 * @Title: getAllProduct
	 * @Description：获取所有产品
	 * 
	 * @param 
	 * @return List<IndexProduct>
	 * @throws：
	 * 
	 */
    @Override
    public List<IndexProduct> getAllProduct() {
        List<IndexProduct> list = null;

        TabProductExample productExample = new TabProductExample();
        productExample.setOrderByClause("date_add");
        List<TabProduct> result = this.tabProductMapper.selectByExample(productExample);

        if (!Tools.objectIsNullOrNot(result)){
            list = new ArrayList<IndexProduct>();

            for (TabProduct tabProduct : result){
                IndexProduct product = new IndexProduct();

                product.setProductId(tabProduct.getProductId());
                product.setName(tabProduct.getName());
                product.setPrice(tabProduct.getPrice());
                product.setOldPrice(tabProduct.getOldPrice());
                product.setImagePath(tabProduct.getImagePath());

                list.add(product);
            }
        }

        return list;
    }
}
